import React from 'react';
import './index.less';

export default class view extends React.Component {
    static propTypes = {
        src: React.PropTypes.string,
        size: React.PropTypes.number,
        imgSize: React.PropTypes.number,
        isDefaultSrc: React.PropTypes.bool,
        shape: React.PropTypes.string, // rect, circle
    };

    static defaultProps = {
        size: 50,
        imgSize: 0,
        isDefaultSrc: true,
        shape: 'rect',
    }

    constructor(props, context) {

        super(props, context);
        // init state;
        this.state = {};
    }

    componentWillMount() {
        this._isMounted = true;
    }

    componentDidMount() {

    }

    componentWillUnmount() {
        this._isMounted = false;
    }

    render() {
        let {src, imgSize, className, userType, isDefaultSrc, cutHeight, onClick, ...restProps} = this.props;
        let typeImg = userType === 2 ? '/assets/images/components/widgets/ReAvatar/images/defaultorg.png' : '/assets/images/components/widgets/ReAvatar/images/defaultportrait.png';
        let defaultSrc = isDefaultSrc ? typeImg : '';

        src = src ? ~src.indexOf('base64') ? src : $$.utils.adaptResourceUrl(src + `?&x-oss-process=image/resize,${cutHeight || 'w'}_${imgSize || this.props.size || 50}`) : defaultSrc;
        if (src || defaultSrc) {
            return (
                <img
                    onClick={(e) => onClick && onClick(e)}
                    src={src}
                    className={className ? `re-avatar ${this.props.shape} ` + className : `re-avatar ${this.props.shape}`}
                    {...restProps}
                />
            );
        } else {
            return (<span className="img-box"></span>);
        }
    }
}
